<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>第八章-依赖管理基础.Chapter&nbsp;8.&nbsp;Dependency Management Basics</title>
<link xmlns:xslthl="http://xslthl.sf.net" type="text/css"
    rel="stylesheet" href="../css/base.css">
<link xmlns:xslthl="http://xslthl.sf.net" type="text/css"
    rel="stylesheet" href="../css/docs.css">
<link xmlns:xslthl="http://xslthl.sf.net" type="text/css"
    rel="stylesheet" href="../css/userguide.css">
<meta content="DocBook XSL Stylesheets V1.75.2" name="generator">
<link rel="home" href="userguide.html" title="Gradle User Guide">
<link rel="up" href="userguide.html" title="Gradle User Guide">
<link rel="prev" href="../ch07/tutorial_java_projects.html"
    title="Chapter&nbsp;7.&nbsp;Java Quickstart">
<link rel="next" href="tutorial_groovy_projects.html"
    title="Chapter&nbsp;9.&nbsp;Groovy Quickstart">
</head>
<body>
    <div class="navheader">
        <div>
            <div class="navbar">
                <a xmlns:xslthl="http://xslthl.sf.net"
                    href="../ch07/tutorial_java_projects.html"
                    title="第七章.Java快速入门  Chapter&nbsp;7.&nbsp;Java Quickstart">上一页</a><span>|</span><a
                    xmlns:xslthl="http://xslthl.sf.net" href="userguide.html"
                    title="Gradle User Guide">返回目录</a><span>|</span><a
                    xmlns:xslthl="http://xslthl.sf.net"
                    href="tutorial_groovy_projects.html"
                    title="第九章.Groovy快速入门 Chapter&nbsp;9.&nbsp;Groovy Quickstart">下一页</a>
            </div>
        </div>
    </div>
    <div class="chapter">
        <div class="titlepage">
            <div>
                <div>
                    <h1 xmlns:xslthl="http://xslthl.sf.net">
                        <a name="artifact_dependencies_tutorial"></a>第八章.依赖管理基础
                    </h1>
                    <h3 xmlns:xslthl="http://xslthl.sf.net">
                        <a name="artifact_dependencies_tutorial"></a>Chapter&nbsp;8.&nbsp;Dependency
                        Management Basics
                    </h3>
                </div>
            </div>
        </div>
        <p>
        本章节介绍如何使用Gradle进行基本的依赖管理.<br>
        This chapter introduces some of the basics of dependency
            management in Gradle.</p>
        <div class="section">
            <div class="titlepage">
                <div>
                    <div>
                        <h2 class="title">
                            <a name="N10568"></a>8.1.&nbsp;神马是依赖管理?
                        </h2>
                        <h4 class="title">
                            <a name="N10568"></a>8.1.&nbsp;What is dependency management?
                        </h4>
                    </div>
                </div>
            </div>
            <p>
                      通俗来讲,依赖管理由如下两部分组成.首先,Gradle需要知道项目构建或运行所需要的一些文件,以便于找到这些需要的文件.
                       我们称这些输入的文件为项目的<em class="firstterm">依赖</em>.其次,你可能需要构建完成后自动上传到某个地方.
                        我们称这些输出为<em class="firstterm">发布</em>.下面来仔细介绍一下这两部分:<br>
                Very roughly, dependency management is made up of two pieces.
                Firstly, Gradle needs to know about the things that your project
                needs to build or run, in order to find them. We call these incoming
                files the <em class="firstterm">dependencies</em> of the project.
                Secondly, Gradle needs to build and upload the things that your
                project produces. We call these outgoing files the <em
                    class="firstterm">publications</em> of the project. Let's look at
                these two pieces in more detail:
            </p>
            <p>
             大部分工程都不太可能完全自给自足,一般你都会用到其他工程的文件.
             比如我工程需要Hibernate就得把它的类库加进来,比如测试的时候可能需要某些额外jar包,例如JDBC驱动或Ehcache之类的Jar包.
             <br>
                Most projects are not completely self-contained. They need
                files built by other projects in order to be compiled or tested and
                so on. For example, in order to use Hibernate in my project, I need
                to include some Hibernate jars in the classpath when I compile my
                source. To run my tests, I might also need to include some
                additional jars in the test classpath, such as a particular JDBC
                driver or the Ehcache jars.</p>
            <p>
               这些文件就是工程的依赖.Gradle需要你告诉它工程的依赖是什么,它们在哪,然后帮你加入构建中.
                     依赖可能需要去远程库下载,比如Maven 或者 Ivy 库.也可以是本地库,甚至可能是另一个工程.
                     我们称这个过程叫<em class="firstterm">依赖解决</em><br>
                These incoming files form the dependencies of the project. Gradle
                allows you to tell it what the dependencies of your project are, so
                that it can take care of finding these dependencies, and making them
                available in your build. The dependencies might need to be
                downloaded from a remote Maven or Ivy repository, or located in a
                local directory, or may need to be built by another project in the
                same multi-project build. We call this process <em class="firstterm">dependency
                    resolution</em>.
            </p>
            <p>
               通常,依赖的自身也有依赖.例如,Hibernate 核心类库就依赖于一些其他的类库.所以,当Gradle构建你的工程时,会去找到这些依赖.
               我们称之为<em class="firstterm">依赖传递</em>.<br>
                Often, the dependencies of a project will themselves have
                dependencies. For example, Hibernate core requires several other
                libraries to be present on the classpath with it runs. So, when
                Gradle runs the tests for your project, it also needs to find these
                dependencies and make them available. We call these <em
                    class="firstterm">transitive dependencies</em>.
            </p>
            <p>
                 大部分工程构建的主要目的是脱离工程使用.例如,生成jar包,包括源代码、文档等,然后发布出去.<br>
                The main purpose of most projects is to build some files that
                are to be used outside the project. For example, if your project
                produces a java library, you need to build a jar, and maybe a source
                jar and some documentation, and publish them somewhere.</p>
            <p>
              这些输出的文件构成了项目的发布内容.Gralde也会为你分担这些工作.你声明了发布到到哪,Gradle就会发布到哪.
             "发布"的意思就是你想做什么.比如,复制到某个目录,上传到Maven或Ivy仓库.或者在其它项目里使用,这些都可以称之为
             <em class="firstterm">发行</em>.<br>
                These outgoing files form the publications of the project. Gradle
                also takes care of this important work for you. You declare the
                publications of your project, and Gradle take care of building them
                and publishing them somewhere. Exactly what "publishing" means
                depends on what you want to do. You might want to copy the files to
                a local directory, or upload them to a remote Maven or Ivy
                repository. Or you might use the files in another project in the
                same multi-project build. We call this process <em class="firstterm">publication</em>.
            </p>
        </div>
        <div class="section">
            <div class="titlepage">
                <div>
                    <div>
                        <h2 class="title">
                            <a name="N10586"></a>8.2.&nbsp;依赖声明
                        </h2>
                        <h4 class="title">
                            <a name="N10586"></a>8.2.&nbsp;Declaring your dependencies
                        </h4>
                    </div>
                </div>
            </div>
            <p>
            来看一下这个脚本里声明依赖的部分:<br>
            Let's look at some dependency declarations. Here's a basic
                build script:</p>
            <div class="example">
                <a name="basicDependencyDeclarations"></a>
                <p class="title">
                    <b>
                    例 8.1. 声明依赖
                    Example&nbsp;8.1.&nbsp;Declaring dependencies</b>
                </p>
                <div class="example-contents">
                    <p>
                        <code class="filename">build.gradle</code>
                    </p>
                    <pre class="programlisting">apply plugin: <span
                            xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'java'</span>

repositories {
    mavenCentral()
}

dependencies {
    compile group: <span xmlns:xslthl="http://xslthl.sf.net"
                            class="hl-string">'org.hibernate'</span>, name: <span
                            xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'hibernate-core'</span>, version: <span
                            xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'3.6.7.Final'</span>
    testCompile group: <span xmlns:xslthl="http://xslthl.sf.net"
                            class="hl-string">'junit'</span>, name: <span
                            xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'junit'</span>, version: <span
                            xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'4.+'</span>
}</pre>
                </div>
            </div>
            <br class="example-break">
            <p>
            这是毛意思呢?这段脚本是这么个意思.首先,Hibernate-core.3.6.7.final.jar这货是编译期必需的依赖.并且这货相关的依赖也会一并被加载进来
            该段脚本同时还声明项目测试阶段需要 4.0版本以上的Junit.同时告诉Gradle可以去Maven中央仓库去找这些依赖.下面的章节会进行更详细的描述.<br>
            <br>
            What's going on here? This build script says a few things
                about the project. Firstly, it states that Hibernate core
                3.6.7.Final is required to compile the project's production source.
                By implication, Hibernate core and its dependencies are also
                required at runtime. The build script also states that any junit
                &gt;= 4.0 is required to compile the project's tests. It also tells
                Gradle to look in the Maven central repository for any dependencies
                that are required. The following sections go into the details.</p>
        </div>
        <div class="section">
            <div class="titlepage">
                <div>
                    <div>
                        <h2 class="title">
                            <a name="configurations">8.3.&nbsp;依赖配置</a>
                        </h2>
                        <h2 class="title">
                            <a name="configurations">8.3.&nbsp;Dependency configurations</a>
                        </h2>
                    </div>
                </div>
            </div>
            <p>
                Gradle中依赖以组的形式来划分不同的<em class="firstterm">配置</em>.
                每个配置都只是一组指定的依赖. 我们称之为<em class="firstterm">依赖配置</em>
                你也可以借由此声明外部依赖.后面我们会了解到,这也可用用来声明项目的发布<br>
                In Gradle dependencies are grouped into <em class="firstterm">configurations</em>.
                A configuration is simply a named set of dependencies. We will refer
                to them as <em class="firstterm">dependency configurations</em>. You
                can use them to declare the external dependencies of your project.
                As we will see later, they are also used to declare the publications
                of your project.
            </p>
            <p>
                Java插件定义了许多标准配置项.这些配置项形成了插件本身的classpath.
                 比如下面罗列的这一些.并且你可以从<a
                    class="xref" href="java_plugin.html#tab:configurations"
                    title="Table&nbsp;23.5.&nbsp;Java 插件 - 依赖配置">Table&nbsp;23.5,
                    &ldquo;Java 插件 - 依赖配置&rdquo;</a>了解到更多详细内容.
                    <br>
                The Java plugin defines a number of standard configurations. These
                configurations represent the classpaths that the Java plugin uses.
                Some are listed below, and you can find more details in <a
                    class="xref" href="java_plugin.html#tab:configurations"
                    title="Table&nbsp;23.5.&nbsp;Java plugin - dependency configurations">Table&nbsp;23.5,
                    &ldquo;Java plugin - dependency configurations&rdquo;</a>.
            </p>
            <div class="variablelist">
                <dl>
                    <dt>
                        <span class="term">compile</span>
                    </dt>
                    <dd>
                        <p>
                        编译范围依赖在所有的classpath中可用，同时它们也会被打包<br>
                        The dependencies required to compile the production source
                            of the project.</p>
                    </dd>
                    <dt>
                        <span class="term">runtime</span>
                    </dt>
                    <dd>
                        <p>
                        runtime依赖在运行和测试系统的时候需要,但在编译的时候不需要.比如,你可能在编译的时候只需要JDBC API JAR,而只有在运行的时候才需要JDBC驱动实现<br>
                        The dependencies required by the production classes at
                            runtime. By default, also includes the compile time dependencies.
                        </p>
                    </dd>
                    <dt>
                        <span class="term">testCompile</span>
                    </dt>
                    <dd>
                        <p>
                        测试期编译需要的附加依赖<br>
                        The dependencies required to compile the test source of the
                            project. By default, also includes the compiled production
                            classes and the compile time dependencies.</p>
                    </dd>
                    <dt>
                        <span class="term">testRuntime</span>
                    </dt>
                    <dd>
                        <p>
                        测试运行期需要<r>
                        The dependencies required to run the tests. By default,
                            also includes the compile, runtime and test compile dependencies.
                        </p>
                    </dd>
                </dl>
            </div>
            <p>
                不同的插件提供了不同的标准配置,你甚至也可以定义属于自己的配置项.具体可查看
                 <a class="xref"
                    href="dependency_management.html#sub:configurations">章节&nbsp;50.3,
                    &ldquo;依赖配置&rdquo;</a> 
                <br>
                Various plugins add further standard configurations. You can also
                define your own custom configurations to use in your build. Please
                see <a class="xref"
                    href="dependency_management.html#sub:configurations">Section&nbsp;50.3,
                    &ldquo;Dependency configurations&rdquo;</a> for the details of defining
                and customizing dependency configurations.
            </p>
        </div>
        <div class="section">
            <div class="titlepage">
                <div>
                    <div>
                        <h2 class="title">
                            <a name="N105C6"></a>8.4.&nbsp;外部依赖
                        </h2>
                         <h4 class="title">
                            <a name="N105C6"></a>8.4.&nbsp;External dependencies
                        </h4>
                    </div>
                </div>
            </div>
            <p>
                                          依赖的类型有很多种,其中有一种类型称之为<em class="firstterm">外部依赖</em>.
                                          这种依赖由外部构建或者在不同的仓库中,例如Maven中央仓库或Ivy仓库中抑或是本地文件系统的某个目录中.<br>
                There are various types of dependencies that you can declare. One
                such type is an <em class="firstterm">external dependency</em>. This
                a dependency on some files built outside the current build, and
                stored in a repository of some kind, such as Maven central, or a
                corporate Maven or Ivy repository, or a directory in the local file
                system.
            </p>
            <p>
                                定义外部依赖需要像下面这样进行依赖配置<br>
            To define an external dependency, you add it to a dependency
                configuration:</p>
            <div class="example">
                <a name="externalDependencies"></a>
                <p class="title">
                    <b>
                                                    例 &nbsp;8.2.&nbsp;定义外部依赖.<br>
                    Example&nbsp;8.2.&nbsp;Definition of an external dependency</b>
                </p>
                <div class="example-contents">
                    <p>
                        <code class="filename">build.gradle</code>
                    </p>
                    <pre class="programlisting">dependencies {
    compile group: <span xmlns:xslthl="http://xslthl.sf.net"
                            class="hl-string">'org.hibernate'</span>, name: <span
                            xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'hibernate-core'</span>, version: <span
                            xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'3.6.7.Final'</span>
}</pre>
                </div>
            </div>
            <br class="example-break">
            <p>
                                           外部依赖包含 <code class="literal">group</code>,<code class="literal">name</code>和<code class="literal">version</code>几个属性.
                                           根据选取仓库的不同,   <code class="literal">group</code>和<code class="literal">version</code>也可能是可选的.<br>
                An external dependency is identified using
                <code class="literal">group</code>
                ,
                <code class="literal">name</code>
                and
                <code class="literal">version</code>
                attributes. Depending on which kind of repository you are using,
                <code class="literal">group</code>
                and
                <code class="literal">version</code>
                may be optional.
            </p>
            <p>
                当然,也有一种更加简洁的方式来声明外部依赖. 采用 : 将三个属性拼接在一起即可.<code class="literal">
                    "<em class="replaceable"><code>group</code></em>:<em
                        class="replaceable"><code>name</code></em>:<em class="replaceable"><code>version</code></em>"
                </code><br>
                There is a shortcut form for declaring external dependencies, which
                uses a string of the form
                <code class="literal">
                    "<em class="replaceable"><code>group</code></em>:<em
                        class="replaceable"><code>name</code></em>:<em class="replaceable"><code>version</code></em>"
                </code>
                .
            </p>
            <div class="example">
                <a name="externalDependencies"></a>
                <p class="title">
                    <b>
                                                    例&nbsp;8.3.&nbsp;快速定义外部依赖<br>
                    Example&nbsp;8.3.&nbsp;Shortcut definition of an external
                        dependency</b>
                </p>
                <div class="example-contents">
                    <p>
                        <code class="filename">build.gradle</code>
                    </p>
                    <pre class="programlisting">dependencies {
    compile <span xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'org.hibernate:hibernate-core:3.6.7.Final'</span>
}</pre>
                </div>
            </div>
            <br class="example-break">
            <p>
                                           更多定义依赖的方式可以参阅
                <a class="xref" href="dependency_management.html#sec:how_to_declare_your_dependencies">章节&nbsp;50.4,
                    &ldquo;如何声明依赖&rdquo;</a>.
                <br>
                To find out more about defining and working with dependencies, have
                a look at <a class="xref"
                    href="dependency_management.html#sec:how_to_declare_your_dependencies">Section&nbsp;50.4,
                    &ldquo;How to declare your dependencies&rdquo;</a>.
            </p>
        </div>
        <div class="section">
            <div class="titlepage">
                <div>
                    <div>
                        <h2 class="title">
                            <a name="N10608"></a>8.5.&nbsp;仓库
                        </h2>
                         <h4 class="title">
                            <a name="N10608"></a>8.5.&nbsp;Repositories
                        </h4>
                    </div>
                </div>
            </div>
            <p>
                Gradle是在一个被称之为<em class="firstterm">仓库</em>的地方找寻所需的外部依赖.
                                            仓库即是一个按   <code class="literal">group</code>,<code class="literal">name</code>和<code class="literal">version</code>
                                            规则进行存储的一些文件.Gradle可以支持不同的仓库存储格式,如Maven和Ivy,并且还提供多种与仓库进行通信的方式,如通过本地文件系统或HTTP.
                 <br>
                How does Gradle find the files for external dependencies? Gradle
                looks for them in a <em class="firstterm">repository</em>. A
                repository is really just a collection of files, organized by
                <code class="literal">group</code>
                ,
                <code class="literal">name</code>
                and
                <code class="literal">version</code>
                . Gradle understands several different repository formats, such as
                Maven and Ivy, and several different ways of accessing the
                repository, such as using the local file system or HTTP.
            </p>
            <p>
            默认情况下,Gradle没有定义任何仓库,你需要在使用外部依赖之前至少定义一个仓库,例如Maven中央仓库. <br>
            By default, Gradle does not define any repositories. You need
                to define at least one before you can use external dependencies. One
                option is use the Maven central repository:</p>
            <div class="example">
                <a name="defineMavenCentral"></a>
                <p class="title">
                    <b>
                    例&nbsp;8.4.&nbsp;使用Maven中央仓库<br>
                    Example&nbsp;8.4.&nbsp;Usage of Maven central repository</b>
                </p>
                <div class="example-contents">
                    <p>
                        <code class="filename">build.gradle</code>
                    </p>
                    <pre class="programlisting">repositories {
    mavenCentral()
}</pre>
                </div>
            </div>
            <br class="example-break">
            <p>
            或者其它远程Maven仓库:<br>
            Or a remote Maven repository:</p>
            <div class="example">
                <a name="defineRemoteMavenRepo"></a>
                <p class="title">
                    <b>
                    例&nbsp;8.5.&nbsp;使用Maven远程仓库<br>
                    Example&nbsp;8.5.&nbsp;Usage of a remote Maven repository</b>
                </p>
                <div class="example-contents">
                    <p>
                        <code class="filename">build.gradle</code>
                    </p>
                    <pre class="programlisting">repositories {
    maven {
        url <span xmlns:xslthl="http://xslthl.sf.net" class="hl-string">"http://repo.mycompany.com/maven2"</span>
    }
}</pre>
                </div>
            </div>
            <br class="example-break">
            <p>
            或者采用Ivy远程仓库<br>
            Or a remote Ivy repository:</p>
            <div class="example">
                <a name="defineRemoteIvyRepo"></a>
                <p class="title">
                    <b>
                                                    例&nbsp;8.6.&nbsp;采用Ivy远程仓库<br>
                    Example&nbsp;8.6.&nbsp;Usage of a remote Ivy directory</b>
                </p>
                <div class="example-contents">
                    <p>
                        <code class="filename">build.gradle</code>
                    </p>
                    <pre class="programlisting">repositories {
    ivy {
        url <span xmlns:xslthl="http://xslthl.sf.net" class="hl-string">"http://repo.mycompany.com/repo"</span>
    }
}</pre>
                </div>
            </div>
            <br class="example-break">
            <p>
                                或者在指定本地文件系统构建的库<br>
            You can also have repositories on the local file system. This
                works for both Maven and Ivy repositories.</p>
            <div class="example">
                <a name="defineRemoteIvyRepo"></a>
                <p class="title">
                    <b>
                                                    例&nbsp;8.7.&nbsp;采用本地Ivy目录<br>
                    Example&nbsp;8.7.&nbsp;Usage of a local Ivy directory</b>
                </p>
                <div class="example-contents">
                    <p>
                        <code class="filename">build.gradle</code>
                    </p>
                    <pre class="programlisting">repositories {
    ivy {
        <span xmlns:xslthl="http://xslthl.sf.net" class="hl-comment">// URL can refer to a local directory</span>
        url <span xmlns:xslthl="http://xslthl.sf.net" class="hl-string">"../local-repo"</span>
    }
}</pre>
                </div>
            </div>
            <br class="example-break">
            <p>
                                  一个项目可以采用多个库.Gradle会按照顺序从各个库里寻找所需的依赖文件,并且一旦找到第一个便停止搜索.<br>
            A project can have multiple repositories. Gradle will look for
                a dependency in each repository in the order they are specified,
                stopping at the first repository that contains the requested module.
            </p>
            <p>
                了解更多库相关的信息请参阅<a class="xref"
                    href="dependency_management.html#sec:repositories">章节&nbsp;50.6,
                    &ldquo;仓库&rdquo;</a>.<br>
                To find out more about defining and working with repositories, have
                a look at <a class="xref"
                    href="dependency_management.html#sec:repositories">Section&nbsp;50.6,
                    &ldquo;Repositories&rdquo;</a>.
            </p>
        </div>
        <div class="section">
            <div class="titlepage">
                <div>
                    <div>
                        <h2 class="title">
                            <a name="N10650"></a>8.6.&nbsp;打包发布
                        </h2>
                         <h4 class="title">
                            <a name="N10650"></a>8.6.&nbsp;Publishing artifacts
                        </h4>
                    </div>
                </div>
            </div>
            <p>
                依赖配置也被用于发布文件<sup>[<a
                    href="#ftn.N10655" name="N10655" class="footnote">3</a>]</sup>
                    我们称之为<em class="firstterm">打包发布</em>,或<em class="firstterm">发布</em><br>
                Dependency configurations are also used to publish files.<sup>[<a
                    href="#ftn.N10655" name="N10655" class="footnote">3</a>]
                </sup> We call these files <em class="firstterm">publication
                    artifacts</em>, or usually just <em class="firstterm">artifacts</em>.
            </p>
            <p>
            插件对于打包提供了完美的支持,所以通常而言无需特别告诉Gradle需要做什么.但是你需要告诉Gradle发布到哪里.
            这就需要在   <code class="literal">uploadArchives</code> 任务中添加一个仓库.下面的例子是如何发布到远程Ivy仓库的:<br>
                The plugins do a pretty good job of defining the artifacts of a
                project, so you usually don't need to do anything special to tell
                Gradle what needs to be published. However, you do need to tell
                Gradle where to publish the artifacts. You do this by attaching
                repositories to the
                <code class="literal">uploadArchives</code>
                task. Here's an example of publishing to a remote Ivy repository:
            </p>
            <div class="example">
                <a name="publishIvyRepository"></a>
                <p class="title">
                    <b>
                                                    例&nbsp;8.8.&nbsp;发布到Ivy仓库.<br>
                    Example&nbsp;8.8.&nbsp;Publishing to an Ivy repository</b>
                </p>
                <div class="example-contents">
                    <p>
                        <code class="filename">build.gradle</code>
                    </p>
                    <pre class="programlisting">uploadArchives {
    repositories {
        ivy {
            credentials {
                username <span xmlns:xslthl="http://xslthl.sf.net"
                            class="hl-string">"username"</span>
                password <span xmlns:xslthl="http://xslthl.sf.net"
                            class="hl-string">"pw"</span>
            }
            url <span xmlns:xslthl="http://xslthl.sf.net"
                            class="hl-string">"http://repo.mycompany.com"</span>
        }
    }
}</pre>
                </div>
            </div>
            <br class="example-break">
            <p>
                                执行<strong class="userinput"><code>gradle uploadArchives</code></strong>,
                                Gradle便会构建并上传你的jar包,同时会生成一个 <code class="filename">ivy.xml</code>一起上传到目标仓库.<br> 
                Now, when you run <strong class="userinput"><code>gradle
                        uploadArchives</code></strong>, Gradle will build and upload your Jar. Gradle will
                also generate and upload an
                <code class="filename">ivy.xml</code>
                as well.
            </p>
            <p>
                当然你也可以发布到Maven仓库中.语法只需稍微一换就可以了.<sup>[<a href="#ftn.N10678" name="N10678"
                    class="footnote">4</a>]</sup><br>
                    p.s:发布到Maven仓库你需要Maven插件的支持,当然,Gradle也会同时产生 <code class="filename">pom.xml</code>一起上传到目标仓库.<br>
                You can also publish to Maven repositories. The syntax is slightly
                different.<sup>[<a href="#ftn.N10678" name="N10678"
                    class="footnote">4</a>]
                </sup> Note that you also need to apply the Maven plugin in order to
                publish to a Maven repository. In this instance, Gradle will
                generate and upload a
                <code class="filename">pom.xml</code>
                .
            </p>
            <div class="example">
                <a name="publishMavenRepository"></a>
                <p class="title">
                    <b>
                                                    例&nbsp;8.9.&nbsp;发布到Maven仓库<br>
                    Example&nbsp;8.9.&nbsp;Publishing to a Maven repository</b>
                </p>
                <div class="example-contents">
                    <p>
                        <code class="filename">build.gradle</code>
                    </p>
                    <pre class="programlisting">apply plugin: <span
                            xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'maven'</span>

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: <span xmlns:xslthl="http://xslthl.sf.net"
                            class="hl-string">"file://localhost/tmp/myRepo/"</span>)
        }
    }
}</pre>
                </div>
            </div>
            <br class="example-break">
            <p>
                了解更多有关发布的内容,请参阅<a class="xref"
                    href="artifact_management.html">第&nbsp;51&nbsp;章, <i>内容发布
                        artifacts</i></a>.<br>
                To find out more about publication, have a look at <a class="xref"
                    href="artifact_management.html">Chapter&nbsp;51, <i>Publishing
                        artifacts</i></a>.
            </p>
        </div>
        <div class="section">
            <div class="titlepage">
                <div>
                    <div>
                        <h2 class="title">
                            <a name="N1068E"></a>8.7.&nbsp;下一步目标
                        </h2>
                         <h4 class="title">
                            <a name="N1068E"></a>8.7.&nbsp;Where to next?
                        </h4>
                    </div>
                </div>
            </div>
            <p>
                了解更多有关依赖的问题,请参阅<a class="xref"
                    href="dependency_management.html">第&nbsp;50&nbsp;章, <i>依赖管理</i></a>,
                     了解更多有关发布的内容,请参阅<a class="xref"
                    href="artifact_management.html">第&nbsp;51&nbsp;章, <i>内容发布
                        artifacts</i></a>.<br>
                For all the details of dependency resolution, see <a class="xref"
                    href="dependency_management.html">Chapter&nbsp;50, <i>Dependency
                        Management</i></a>, and for artifact publication see <a class="xref"
                    href="artifact_management.html">Chapter&nbsp;51, <i>Publishing
                        artifacts</i></a>.
            </p>
            <p>
            若对DSL感兴趣 ,请看<a class="ulink"
                    href="../../dsl/org.gradle.api.Project.html#org.gradle.api.Project:configurations(groovy.lang.Closure)"
                    target="_top"><code class="classname">Project.configurations{}</code></a>,
                <a class="ulink"
                    href="../../dsl/org.gradle.api.Project.html#org.gradle.api.Project:repositories(groovy.lang.Closure)"
                    target="_top"><code class="classname">Project.repositories{}</code></a>
                and <a class="ulink"
                    href="../../dsl/org.gradle.api.Project.html#org.gradle.api.Project:dependencies(groovy.lang.Closure)"
                    target="_top"><code class="classname">Project.dependencies{}</code></a>.<br>
                If you are interested in the DSL elements mentioned here, have a
                look at <a class="ulink"
                    href="../../dsl/org.gradle.api.Project.html#org.gradle.api.Project:configurations(groovy.lang.Closure)"
                    target="_top"><code class="classname">Project.configurations{}</code></a>,
                <a class="ulink"
                    href="../../dsl/org.gradle.api.Project.html#org.gradle.api.Project:repositories(groovy.lang.Closure)"
                    target="_top"><code class="classname">Project.repositories{}</code></a>
                and <a class="ulink"
                    href="../../dsl/org.gradle.api.Project.html#org.gradle.api.Project:dependencies(groovy.lang.Closure)"
                    target="_top"><code class="classname">Project.dependencies{}</code></a>.
            </p>
            <p>
                另外,继续顺着手册学习其它章节内容吧.~<br>
                Otherwise, continue on to some of the other <a class="link"
                    href="tutorials.html">tutorials</a>.
            </p>
        </div>
        <div class="footnotes">
            <br>
            <hr align="left" width="100">
            <div class="footnote">
                <p>
                <sup>[<a href="#N10655" name="ftn.N10655" class="para">3</a>]
                    </sup>这让人感觉有点囧,我们正在尝试逐步分离两种概念.<br>
                    <sup>[<a href="#N10655" name="ftn.N10655" class="para">3</a>]
                    </sup>We think this is confusing, and we are gradually teasing apart the
                    two concepts in the Gradle DSL.
                </p>
            </div>
            <div class="footnote">
                <p>
                 <sup>[<a href="#N10678" name="ftn.N10678" class="para">4</a>]
                    </sup>我们也在努力改进语法让发布到Maven仓库不那么费劲.<br>
                    <sup>[<a href="#N10678" name="ftn.N10678" class="para">4</a>]
                    </sup>We are working to make the syntax consistent for resolving from and
                    publishing to Maven repositories.
                </p>
            </div>
        </div>
    </div>
    <div class="navfooter">
        <div>
            <div class="navbar">
                <a xmlns:xslthl="http://xslthl.sf.net"
                    href="../ch07/tutorial_java_projects.html"
                    title="第七章;Java 构建入门">上一页</a><span>|</span><a
                    xmlns:xslthl="http://xslthl.sf.net" href="../userguide.html"
                    title="返回目录">返回目录</a><span>|</span><a
                    xmlns:xslthl="http://xslthl.sf.net"
                    href="../tutorial_groovy_projects.html"
                    title="第九章;Groovy 构建入门">下一页</a>
            </div>
        </div>
    </div>
</body>
</html>